<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>
        用户组管理
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/css/main.css}" media="all">
</head>

<body>
<div class="x-body">
    <form action="" method="post" class="layui-form layui-form-pane" id="auth_groupadd">
        <input type="hidden" name="id" value=""/>
        <div class="layui-form-item">
            <label for="role_code" class="layui-form-label">
                <span class="x-red">*</span>角色编码
            </label>
            <div class="layui-input-inline" id="sss">
                <select id="a_role_code" name="role_code" >
                    <option value="" selected="selected">--请选择--</option>
                    <option  value="vil_role01">vil_role01</option>
                    <option  value="vil_role02">vil_role02</option>
                    <option  value="vil_role03">vil_role03</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="role_name" class="layui-form-label">
                <span class="x-red">*</span>角色名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="a_role_name" name="role_name"
                       class="layui-input" value="" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="1" title="启用" checked="checked">
                <div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon layui-anim-scaleSpring"></i>
                    <div>启用</div>
                </div>
                <input type="radio" name="status" value="0" title="禁用" checked="checked">
                <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i>
                    <div>禁用</div>
                </div>


            </div>
        </div>
        <div class="layui-form-item ">
            <label class="layui-form-label">
                拥有权限
            </label>
            <div class="layui-input-inline">
                <input type="text" id="a_describes" name="describes"
                       class="layui-input" value="" readonly='true'>
            </div>
        </div>
        <div class="layui-form-item ">
            <label class="layui-form-label">
                创建者
            </label>
            <div class="layui-input-inline">
                <input type="text" id="a_createBy" name="createdBy"
                       class="layui-input" th:value="${a.login_code}" readonly='true'>
            </div>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn" lay-submit="" lay-filter="add">保存</button>
        </div>
    </form>
</div>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8">
</script>
<script th:src="@{/js/x-layui.js}" charset="utf-8">
</script>
<script th:src="@{/js/jquery-1.11.3.js}" charset="utf-8">
</script>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form()
            , layer = layui.layer;


        $('#sss').click(function () {
            // alert("1");
            var role_code = $('#a_role_code').val();
            if (role_code=='vil_role01') {
                // $('#a_role_name').val('超级管理员');
                $('#a_describes').val("拥有所有权限");
            } else if (role_code =='vil_role02') {
                // $('#a_role_name').val("普通管理员");
                $('#a_describes').val('拥有基础权限');
            } else {
                // $('#a_role_name').val("普通用户");
                $('#a_describes').val('操作个人信息');
            }
        });

        //监听提交
        form.on('submit(add)', function (data) {
            var auth_groupadd = $("#auth_groupadd").serialize();
            var role_code = $("select[name='role_code']").val();
            var data = data.field;
            if (role_code == "") {
                layer.msg("用户组编码不能为空", {icon: 5, time: 2000});
                return false;
            }
            $.ajax({
                type: "post",
                url: "/administrator/addGroup",
                data: data,
                dataType: "json",
                success: function (data) {
                    if (data.status == 1) {
                        layer.msg(data.msg, {icon: 1, time: 1000});
                        setTimeout(function () {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }, 1000);
                        return false;
                    } else {
                        layer.msg(data.msg, {icon: 5, time: 2000});
                        return false;
                    }
                }
            })
            return false;
        });


    });
</script>


</body>

</html>